package com.ktmall.pojo;

import lombok.Getter;
import lombok.Setter;

import java.util.List;

/**
 * 分页工具类
 *
 * @version v1.0
 * @Author 郴州科泰
 * @Create 2024-07-19 - 15:27
 */
@Getter
public class Page<T> {
    protected Integer currPageNo;  // 当前页码
    @Setter
    protected Integer pageSize;  // 每页显示的数据行数
    protected Integer totalCount;  //总的记录数
    protected Integer totalPageCount; //总的页数
    @Setter
    protected List<T> list;   // 分页列表数据

    public void setCurrPageNo(Integer currPageNo) {
        //对传递的页码进行边界判断
        if (currPageNo < 1) {
            currPageNo = 1;
        }
        if (this.totalPageCount > 0 && currPageNo > this.totalPageCount) {
            currPageNo = this.totalPageCount;
        }
        this.currPageNo = currPageNo;
    }

    public void setTotalCount(Integer totalCount) {
        this.totalCount = totalCount;
        // 计算总的页数
        this.totalPageCount = this.totalCount % this.pageSize == 0 ? this.totalCount / this.pageSize : this.totalCount / this.pageSize + 1;
    }

}
